package simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ProducerDemon {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory =new ConnectionFactory();
        connectionFactory.setUsername("study");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("study");
        connectionFactory.setPassword("123456");
        connectionFactory.setHost("192.168.46.107");
        //创建连接 Connection
        Connection connection = connectionFactory.newConnection();
        //创建 信道:Channel
        Channel channel = connection.createChannel();
        //声明交换机,这里使用默认的交换机

        //声明队列
        channel.queueDeclare("study",false,false,false,null);
        //发送消息
        String msg="你好";
        channel.basicPublish("","study",null,msg.getBytes());
        System.out.println("消息发送成功");
        channel.close();
        connection.close();


    }
}
